package com.fenghongzhang.day011;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectChangeListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.contrarywind.listener.OnItemSelectedListener;
import com.contrarywind.view.WheelView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private WheelView wheel;

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        wheel = (WheelView) findViewById(R.id.wheel);

        final List<String> list = new ArrayList<>();
        list.add("我的中国心");
        list.add("北国之春");
        list.add("鹿港小镇");

        wheel.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                Log.i(TAG, "onItemSelected: " + list.get(index));
            }
        });

//        wheel.setCyclic(false);

        ArrayWheelAdapter<String> stringArrayWheelAdapter = new ArrayWheelAdapter<>(list);
        wheel.setAdapter(stringArrayWheelAdapter);

    }

    public void btn(View view) {
        final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        TimePickerView pvTime = new TimePickerBuilder(MainActivity.this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                String format = simpleDateFormat.format(date);
                Toast.makeText(MainActivity.this, format, Toast.LENGTH_SHORT).show();
            }
        }).build();
        pvTime.show();//显示时间选择器
    }

    public void btn1(View view) {
        final List<String> options1Items = new ArrayList<>();
        options1Items.add("射雕英雄传");
        options1Items.add("神雕侠侣");
        options1Items.add("鹿鼎记");

        List<String> options2Items_01 = new ArrayList<>();
        options2Items_01.add("郭靖");
        options2Items_01.add("黄蓉");
        options2Items_01.add("杨铁心");
        options2Items_01.add("欧阳克");
        List<String> options2Items_02 = new ArrayList<>();
        options2Items_02.add("小龙女");
        options2Items_02.add("杨过");
        options2Items_02.add("大雕");
        List<String> options2Items_03 = new ArrayList<>();
        options2Items_03.add("小柜子");
        options2Items_03.add("康熙");
        options2Items_03.add("康亲王");
        options2Items_03.add("鳌拜");

        final List<List<String>> options2Items = new ArrayList<>();
        options2Items.add(options2Items_01);
        options2Items.add(options2Items_02);
        options2Items.add(options2Items_03);


        OptionsPickerView optionsPickerView = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                String tx = options1Items.get(options1) + options2Items.get(options1).get(options2);
                Toast.makeText(getBaseContext(), tx, Toast.LENGTH_SHORT).show();
            }
        }).setOptionsSelectChangeListener(new OnOptionsSelectChangeListener() {
            @Override
            public void onOptionsSelectChanged(int options1, int options2, int options3) {
                String str = "options1: " + options1 + "\noptions2: " + options2 + "\noptions3: " + options3;
                Toast.makeText(MainActivity.this, str, Toast.LENGTH_SHORT).show();
            }
        }).build();

        optionsPickerView.setPicker(options1Items, options2Items);
        optionsPickerView.show();


    }
}
